package pda;

import java.util.Objects;

/**
 * @author haoly
 * @title PDAConfiguration
 * @date 2025/4/21 10:10
 * @description TODO
 */
public class PDAConfiguration<T> {
    private final T state;

    private final Stack<Character> stack;

    private final T STUCK_STATE = (T)new Object();

    public PDAConfiguration(T state, Stack<Character> stack) {
        this.state = state;
        this.stack = stack;
    }

    public T getState() {
        return state;
    }

    public Stack<Character> getStack() {
        return stack;
    }

    @Override
    public String toString() {
        return "#struct PDAConfiguration state=" + state + ", stack = " + stack;
    }

    public PDAConfiguration<T> stuck(){
        return new PDAConfiguration<>(STUCK_STATE, stack);
    }

    public Boolean isStuck(){
        return Objects.equals(state, STUCK_STATE);
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.state, this.stack);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof PDAConfiguration<?>)) {
            return false;
        }
        PDAConfiguration<T> otherConfig = (PDAConfiguration<T>)obj;

        return Objects.equals(this.state, otherConfig.getState()) &&
                Objects.equals(this.stack, otherConfig.getStack());
    }
}
